/**
 * 所有版权归 广西梧州 陈锦韬 所有
 *
 * @Title: MyAuthenticationSuccessHandler
 * @Package com.rx.bean
 * @Description: 成功返回
 * @author: 陈锦韬
 * @date: 2020\5\22 0022
 * @version V1.0
 * @Copyright: 2020 陈锦韬  All rights reserved.
 */
package com.rx.core.bean;

import com.alibaba.fastjson.JSON;
import com.rx.core.base.RxResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.SimpleUrlLogoutSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author: Administrator
 * @Description: 成功登出返回
 * @date: 2020\5\22 0022
 */
@Component
@Slf4j
public class RxLogoutSuccessHandler extends SimpleUrlLogoutSuccessHandler {

    @Override
    public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response,
                                Authentication authentication) throws IOException, ServletException {
        // TODO:清除缓存。
        log.info("成功登出");


        //处理编码方式，防止中文乱码的情况
        response.setContentType("text/json;charset=utf-8");
        //塞到HttpServletResponse中返回给前台
        RxResponse result = RxResponse.ok();
        response.getWriter().write(JSON.toJSONString(result));
        //super.handle(request, response, authentication);
    }

}
